﻿using BUS;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace QLBV_Nhom8
{
    public partial class frmHoaDonThanhToanDichVu : Form
    {
        public frmHoaDonThanhToanDichVu()
        {
            InitializeComponent();
        }

        private void btnTim_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(txtMaPhieuKham.Text))
            {
                string ma = txtMaPhieuKham.Text;
                if (ma.StartsWith("PKB"))
                    ma = ma.Replace("PKB", "");


                string sql = @"select distinct ChiTietPhieuXetNghiem.TenXN, DonGia, HoTen from PhieuKhamBenh, PhieuXetNghiem, ChiTietPhieuXetNghiem, HoSoBenhNhan
where PhieuKhamBenh.MaPKB = PhieuXetNghiem.MaPKB and PhieuXetNghiem.MaPXN = ChiTietPhieuXetNghiem.MaPhieuXN 
and HoSoBenhNhan.MaHoSoBenhNhan = PhieuKhamBenh.MaHoSoBenhNhan
and PhieuKhamBenh.MaPKB = " + ma;
                
                


                dataGridView1.DataSource = ChiTietPhieuXetNghiemBUS.LayDanhSachChiTietPhieuXetNghiemTheoMaPKB(sql);



                dataGridView1.Columns[2].Visible = false;
                if (dataGridView1.Rows.Count > 0)
                    txtTenBenhNhan.Text = dataGridView1.Rows[0].Cells[2].Value.ToString();
                else
                    txtTenBenhNhan.Text = "";

                double tong = 0;
                for (int i = 0; i < dataGridView1.Rows.Count; i++)
                {
                    tong += Convert.ToInt32(dataGridView1.Rows[i].Cells[1].Value);
                }

                txtTongTien.Text = tong.ToString();
            }
            else
            {
                MessageBox.Show("Nhập Mã Phiếu Khám Bệnh");
            }
        }
    }
}
